package com.aliyun.edu.advanced.development.thread.achieve;

/**
 * @author xiaoming
 * @version 1.0
 * @date 2019-02-17 21:00
 **/
public class demo2 {
    public static void main(String[] args) {

        MyThread2 t1 = new MyThread2("线程A");
        MyThread2 t2 = new MyThread2("线程A");

        new Thread(t1).start();
        new Thread(t2).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("匿名内部类");
            }
        }).start();

        new Thread(
                ()-> System.out.println("lambda 线程")
        ).start();

    }
}

/**
 * 一个线程的主体类
 */
class MyThread2 implements Runnable {
    private String title;

    public MyThread2(String title) {
        this.title = title;
    }

    // 所有线程从这里开始执行
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(this.title + ", i = " + i);
        }
    }
}